package org.robot.component;

public class Rule {
    private String selector;
    private String regex;
    private String attr;
    private String type;
    
    public Rule() {}
    
    public Rule(String type) {
    	this.type = type;
    }
    
    public Rule(String selector, String regex, String attr, String type) {
        this.selector = selector;
        this.regex = regex;
        this.attr = attr;
        this.type = type;
    }
    

	@Deprecated
    public static Rule createRegexRule(String regex, String type) {
        return createRule("a[href]", regex, type);
    }
    
    @Deprecated
    public static Rule createSelectorRule(String selector, String type) {
        return createRule(selector, ".+", type);
    }
    
    @Deprecated
    public static Rule createRule(String selector, String regex, String type) {
        return createRule(selector, regex, "href", type);
    }
    
    @Deprecated
    public static Rule createRule(String selector, String regex, String attr, String type) {
        return new Rule(selector, regex, attr, type);
    }
    
    public static Rule createRegexRule(String regex) {
    	return createRule("a[href]", regex);
    }
    
    public static Rule createSelectorRule(String selector) {
    	return createRule(selector, ".+");
    }
    
    public static Rule createRule(String selector, String regex) {
    	return createCompleteRule(selector, regex, "href");
    }
    
    public static Rule createCompleteRule(String selector, String regex, String attr) {
    	return new Rule(selector, regex, attr, null);
    }

    public boolean isAddByHand() {
        return (selector == null && regex == null && attr == null);
    }
    
    public String getSelector() {
		return selector;
	}

	public Rule setSelector(String selector) {
		this.selector = selector;
		return this;
	}

	public String getRegex() {
		return regex;
	}

	public Rule setRegex(String regex) {
		this.regex = regex;
		return this;
	}

	public String getAttr() {
		return attr;
	}

	public Rule setAttr(String attr) {
		this.attr = attr;
		return this;
	}

	public String getType() {
		return type;
	}

	public Rule setType(String type) {
		this.type = type;
		return this;
	}

	@Override
    public String toString() {
        return "Rule [selector=" + selector + ", regex=" + regex + ", attr=" + attr + ", type=" + type + "]";
    }


    
    
    
}
